<template>
  <div class="home-swipe">
    <van-search
      v-model="search"
      placeholder="请输入搜索关键词"
      input-align="center"
      @focus="onFocus"
      @search="onSearch"
    />
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in bannerData" :key="item.id">
        <img :src="item.imageUrl" />
      </van-swipe-item>
    </van-swipe>
  </div>
</template>
<script>
import { Toast } from "vant";
import axios from "axios";
export default {
  data() {
    return {
      search: "",
      bannerData: [],
    };
  },
  created() {
    this.getBanner();
  },
  methods: {
    getBanner() {
      axios
        .get("/api/banner")
        .then((response) => {
          console.log(response.data);
          let resData = response.data;
          if (resData.code == 200) {
            this.bannerData = resData.banners;
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    onFocus() {
      Toast("触发获得焦点");
    },
    onSearch(val) {
      Toast(val);
    },
  },

  //   mounted() {
  //     this.getBanner();
  //   },
};
</script>
<style scoped>
.my-swipe .van-swipe-item img {
  width: 90%;
  border-radius: 2rem;
}
</style>
